<?php

/* @var $this \yii\web\View */
?>
<script>
    var $permissions = {};

    Vue.prototype.$local_set_permissions = function (permissions) {
        let sp = window.localStorage;
        sp.permissions = JSON.stringify(permissions)
    }

    Vue.prototype.$local_load_permissions = function () {
        if (Object.keys($permissions).length == 0) {
            let sp = window.localStorage;
            if (!sp.permissions || sp.permissions == 'undefined')
                return null;

            $permissions = JSON.parse(sp.permissions);
        }

        return $permissions;
    }

    Vue.prototype.$can = function (object) {
        return true;

        let permissions = this.$local_load_permissions();

        for (let i = 0; i < object.length; i++) {
            permissions = permissions[object[i]];
            if(permissions === undefined)
                return false;
        }

        return true;
    }
</script>
